﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class FEEANDCOST
    {
        public DataTable SEARCH_ALL(FeeAndCost FeeAndCost, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@TransactionDate", FeeAndCost.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@DataType", FeeAndCost.DataType.AsDBValue()));
                lstParams.Add(new SqlParameter("@SOURCEDATAID", FeeAndCost.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ACCOUNTNO", FeeAndCost.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", FeeAndCost.FeeAndCostTypeID.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOST_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int iFEEANDCOSTID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FEEANDCOSTID", iFEEANDCOSTID));
                dt = Utility.StoredProcDataTable("SPR_FEEANDCOST_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(FeeAndCost FeeAndCost)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FEEANDCOSTID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", FeeAndCost.TransactionDate));
                lstParams.Add(new SqlParameter("@DATATYPE", FeeAndCost.DataType));
                lstParams.Add(new SqlParameter("@SOURCEDATAID", FeeAndCost.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", FeeAndCost.AccountNo));
                lstParams.Add(new SqlParameter("@FEEANDCOSTTYPEID", FeeAndCost.FeeAndCostTypeID));
                lstParams.Add(new SqlParameter("@AMOUNT", FeeAndCost.Amount));
                lstParams.Add(new SqlParameter("@CreatedDate", FeeAndCost.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", FeeAndCost.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", FeeAndCost.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", FeeAndCost.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", FeeAndCost.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", FeeAndCost.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", FeeAndCost.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", FeeAndCost.UpdatedBranch));

                utility.ExecuteStoredProc("SPR_FEEANDCOST_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(FeeAndCost FeeAndCost)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FEEANDCOSTID", FeeAndCost.FeeAndCostID));
                lstParams.Add(new SqlParameter("@TransactionDate", FeeAndCost.TransactionDate));
                lstParams.Add(new SqlParameter("@DATATYPE", FeeAndCost.DataType));
                lstParams.Add(new SqlParameter("@SOURCEDATAID", FeeAndCost.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", FeeAndCost.AccountNo));
                lstParams.Add(new SqlParameter("@FEEANDCOSTTYPEID", FeeAndCost.FeeAndCostTypeID));
                lstParams.Add(new SqlParameter("@AMOUNT", FeeAndCost.Amount));
                lstParams.Add(new SqlParameter("@UpdatedDate", FeeAndCost.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", FeeAndCost.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", FeeAndCost.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", FeeAndCost.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_FEEANDCOST_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(int iFEEANDCOSTID)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FEEANDCOSTID", iFEEANDCOSTID));
                iNum = (int)Utility.ExecuteStoredProc("SPR_FEEANDCOST_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

    }
}
